﻿@model IEnumerable<FCNS.ERP.Models.ErpJxcOrderIO>

@{
    ViewBag.Title = "库存过账";
    Layout = "~/Views/Jxc/_Layout.cshtml";
}

<h2>@ViewBag.Title</h2>
<script type="text/javascript">
    $(document).ready(function () {
        $(".btn-success").click(function () {
            var tr = $(this).parent().parent();
            var all = Number(tr.children("td:eq(2)").text());
            var ok = Number(tr.children("td:eq(3)").text());
            var count = Number(tr.children("td:eq(4)").children().val());
            if (count > 0) {
                var remain = all - ok - count;
                if (remain < 0) {
                    alert("待审核数量错误");
                    return;
                }
                //更新已审核数量 
                tr.children("td:eq(3)").text(ok + count);
                //更新待审核参数
                tr.children("td:eq(4)").children().val(remain);
                tr.children("td:eq(4)").children().attr("max", remain);
               // alert($(this).prev().val() + "  " + count);
                $.post("/Jxc/OrderIoConfirm", { id: $(this).prev().val(), count: count });
            }
            else {
                alert("待审核数量不能为空")
            }
        });

        $(".btn-danger").click(function () {
            $(".btn-success").click();
            alert("过账完成");
            window.location.replace("/Jxc/StoreOrder?flag=" +@ViewData["Flag"])
        });
    });
</script>

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.ProductId)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.StorePrice)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Count)
        </th>

        <th>
            @Html.DisplayNameFor(model => model.CountIO)
        </th>
        <th>待审核数量</th>
        <th><input type="button" value="一键过账" class="btn btn-danger" /></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Product.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.StorePrice)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.Count)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.CountIO)
            </td>
            <td>
                @{
                    var vr = item.Count - item.CountIO;
                    <input type="number" min="0" max=@vr value=@vr  />
                }
            </td>
            <td>
                @Html.HiddenFor(modelItem => item.Id)
                <input type="button" value="保存"  class="btn btn-success" />
            </td>
        </tr>
    }

</table>
